package com.goldenautumn.prefabricate.utils

import java.math.BigDecimal
import java.math.RoundingMode

class Money(amount: String) {

    private val value: BigDecimal = BigDecimal(amount)

    operator fun plus(money: Money): Money {
        return Money(value.add(money.value).setScale(2, RoundingMode.HALF_UP).toString())
    }

    operator fun minus(money: Money): Money {
        return Money(value.subtract(money.value).setScale(2, RoundingMode.HALF_UP).toString())
    }

    operator fun times(money: Money): Money {
        return Money(value.multiply(money.value).setScale(2, RoundingMode.HALF_UP).toString())
    }

    operator fun div(money: Money): Money {
        return Money(value.divide(money.value, 2, RoundingMode.HALF_UP).toString())
    }

    override fun toString(): String {
        return value.toString()
    }

}